package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashAccountT;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashReceivable;
import sanrenxing.dayEnd.backRepertoryTotal.domain.FundAllocation;
import sanrenxing.dayEnd.backRepertoryTotal.domain.FundSetupT;

import java.util.List;

/**接口类
 *
 */
@Repository
public interface FundAllocationDao {
    /**
     * 添加一行数据
     * @param fundAllocation 调拨对象
     * @return 0添加失败，1添加成功
     */
    @Insert("insert into fundAllocation values(seqFundAllocation.nextval,#{fundId},#{caId},#{reType},#{reMoney},#{businDate},#{reDate},#{mark},#{dial})")
    public int add(FundAllocation fundAllocation);

    /**
     * 删除一行数据
     * @param tofId 调拨编号
     * @return 0删除失败，1删除成功
     */
    @Delete("delete from fundAllocation where tofId=#{tofId}")
    public int delete(int tofId);

    /**
     * 修改一行数据
     * @param fundAllocation 调拨对象
     * @return 0修改失败，1修改成功
     */
    @Update("update fundAllocation set fundId=#{fundId},caId=#{caId},reType=#{reType},reMoney=#{reMoney},businDate=#{businDate},reDate=#{reDate},mark=#{mark},dial=#{dial} where tofId=#{tofId}")
    public int update(FundAllocation fundAllocation);

    /**
     * 查询所有调拨
     * @return 调拨对象集合
     */
    @Select("select * from(select a.*,rownum rn from (select * from fundAllocation) a where rownum < #{rows}) where rn>#{start} and 1=1 ${condition}")
    public List<FundAllocation> findAll(@Param("start") int start, @Param("rows") int rows, @Param("condition") String condition);

    /**
     * 按条件统计记录数
     * @param condition 统计条件
     * @return 记录的行数
     */
    @Select("select count(*) from fundAllocation where 1=1 ${condition}")
    public int count(@Param("condition") String condition);

    /**
     * 资金调拨是查询基金
     * @return
     */
    @Select("select * from fundSetup")
    public List<FundSetupT> queryFundSetpT();

    /**
     * 资金调拨查询现金账户
     * @return
     */
    @Select("select * from cashAccount")
    public List<CashAccountT> queryCashAccountT();

    /**
     * 添加现金应收应付数据
     * @param cashReceivable
     */
    @Insert("Insert into cashReceivable(Id,businDate,caId,businType,capFlow,money,fundId,states) " +
            "values(seqCashReceivable.nextval,sysdate,#{caId},#{businType},#{capFlow},#{money},#{fundId},#{states})")
    public void addSec(CashReceivable cashReceivable);
}
